package com.jvtd.demo.im.listener;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.view.View;
import android.widget.Toast;

import com.jvtd.rong_im.listener.BaseConversationClickListener;

import io.rong.imlib.model.Conversation;
import io.rong.imlib.model.Message;
import io.rong.imlib.model.UserInfo;

/*
 * Create by Jack Zhang
 */
public class MyConversationClickListener extends BaseConversationClickListener
{
  private final Context context;

  public MyConversationClickListener(Context context)
  {
    this.context = context;
  }

  @Override
  public boolean onUserPortraitClick(Context context, Conversation.ConversationType conversationType, UserInfo user, String targetId)
  {
    showToastMsg("点击了" + user.getName() + "的头像");
    return super.onUserPortraitClick(context, conversationType, user, targetId);
  }

  @Override
  public boolean onUserPortraitLongClick(Context context, Conversation.ConversationType conversationType, UserInfo user, String targetId)
  {
    showToastMsg("长按了" + user.getName() + "的头像");
    return super.onUserPortraitLongClick(context, conversationType, user, targetId);
  }

  @Override
  public boolean onMessageClick(Context context, View view, Message message)
  {
    showToastMsg("点击了消息");
    return super.onMessageClick(context, view, message);
  }

  @Override
  public boolean onMessageLinkClick(Context context, String link, Message message)
  {
    showToastMsg("点击了链接消息");
    return super.onMessageLinkClick(context, link, message);
  }

  @Override
  public boolean onMessageLongClick(Context context, View view, Message message)
  {
    showToastMsg("长按了消息");
    return super.onMessageLongClick(context, view, message);
  }

  private void showToastMsg(String string)
  {
    new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(context, string, Toast.LENGTH_SHORT).show());
  }
}
